﻿using System.Runtime.InteropServices;

namespace DimsMapper.Proto
{
    static class Prototypes
    {
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct CommonProtoData
        {
            public int protoID;
            public int descID;
            public int frmID;
            public int lightDis;
            public int lightInt;
            public int flags;
            public int flagsExt;
        }

        public struct CommonExtProtoData
        {
            public int scriptID;
        }

        // Cтруктура для файла типа Critters
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct CritterProtoData
        {
            public struct CritterStats
            {
                public int Strength;
                public int Perception;
                public int Endurance;
                public int Charisma;
                public int Intelligence;
                public int Agility;
                public int Luck;
                public int HP;
                public int AP;
                public int AC;
                public int UnarmedDmg;
                public int MeleeDmg;
                public int Weight;
                public int Sequence;
                public int Healing;
                public int Critical;
                public int Better;

                public int DTNormal;
                public int DTLaser;
                public int DTFire;
                public int DTPlasma;
                public int DTElectrical;
                public int DTEMP;
                public int DTExplode;
                public int DRNormal;
                public int DRLaser;
                public int DRFire;
                public int DRPlasma;
                public int DRElectrical;
                public int DREMP;
                public int DRExplode;
                public int DRRadiation;
                public int DRPoison;

                public int Age;
                public int Gender;
            }

            public struct Skills
            {
                public int SmallGuns;
                public int BigGuns;
                public int EnergyGun;
                public int Unarmed;
                public int Melee;
                public int Throwing;
                public int FirstAid;
                public int Doctor;
                public int Sneak;
                public int Lockpick;
                public int Steal;
                public int Traps;
                public int Science;
                public int Repair;
                public int Speech;
                public int Barter;
                public int Gambling;
                public int Outdoorsman;
            }

            public int HeadFID;
            public int AIPacket;
            public int TeamNum;
            public int CritterFlags;
            public CritterStats baseStats;  // Base stats
            public CritterStats bonusStats; // Bonus to base stats
            public Skills skills;           // Bonus points to skills
            public int BodyType;
            public int ExpVal;
            public int KillType;
            public int DamageType;
        }

        ///////////////////////////////////////////////////////////////////////

        // Cтруктуры для файла типа Items
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct CommonItemProtoData
        {
            public int  ObjType;
            public int  MaterialID;
            public int  Size;
            public int  Weight;
            public int  Cost;
            public int  InvFID;
            public byte SoundID;
        }

        // Weapon
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct WeaponItemProto
        {
            public int  AnimCode;
            public int  MinDmg;
            public int  MaxDmg;
            public int  DmgType;
            public int  MaxRangePrimary;
            public int  MaxRangeSecond;
            public int  ProjPID;
            public int  MinST;
            public int  APCostPrimary;
            public int  APCostSecond;
            public int  CritFail;
            public int  Perk;
            public int  Rounds;
            public int  Caliber;
            public int  AmmoPID;
            public int  MaxAmmo;
            public byte WeaponSoundID;
        }

        // Armor
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct ArmorItemProto
        {
            public int AC;
            public int DRNormal;
            public int DRLaser;
            public int DRFire;
            public int DRPlasma;
            public int DRElectrical;
            public int DREMP;
            public int DRExplode;
            public int DTNormal;
            public int DTLaser;
            public int DTFire;
            public int DTPlasma;
            public int DTElectrical;
            public int DTEMP;
            public int DTExplode;
            public int Perk;
            public int MaleFID;
            public int FemaleFID;
        }

        // Ammo
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct AmmoItemProto
        {
            public int Caliber;
            public int Quantity;
            public int ACAdjust;
            public int DRAdjust;
            public int DamMult;
            public int DamDiv;
        }

        // Drugs
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct DrugsItemProto
        {
            public int Stat0;
            public int Stat1;
            public int Stat2;
            public int InstantAmount0;
            public int InstantAmount1;
            public int InstantAmount2;
            public int DelayDuration1; // задержка перед применением эффектов Delay1
            public int Delay1Amount0;
            public int Delay1Amount1;
            public int Delay1Amount2;
            public int DelayDuration2; // задержка перед применением эффектов Delay2
            public int Delay2Amount0;
            public int Delay2Amount1;
            public int Delay2Amount2;
            public int AddictionRate;
            public int W_Effect;
            public int W_Onset;
        }

        // Container
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct ContainerItemProto
        {
            public int  MaxSize;
            public int  Flags;
        }

        // Misc
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct MiscItemProto
        {
            public int  PowerPID;
            public int  PowerType;
            public int  Charges;
        }

        // Key
        public struct KeyItemProto
        {
            public int  Unknown;
        }

        [StructLayout(LayoutKind.Explicit, Pack = 1)]
        public struct ItemProtoData
        {
            [FieldOffset(0)]
            public ArmorItemProto armor;

            [FieldOffset(0)]
            public WeaponItemProto weapon;

            [FieldOffset(0)]
            public AmmoItemProto ammo;

            [FieldOffset(0)]
            public DrugsItemProto drugs;

            [FieldOffset(0)]
            public ContainerItemProto container;

            [FieldOffset(0)]
            public MiscItemProto misc;

            [FieldOffset(0)]
            public KeyItemProto key;
        }

        ///////////////////////////////////////////////////////////////////////

        abstract internal class SceneryProtoCommonData
        {
            protected int common; // общее поле
        }

        public class SceneryProtoData
        {
            public int  Material;
            public int  Unused;
            public byte SoundID;
        }

        public class SceneryProtoGenericData : SceneryProtoCommonData
        {
            public int Unknown
            {
                set { base.common = value ; }
                get { return base.common; }
            }
        }

        public class SceneryProtoDoorData : SceneryProtoCommonData
        {
            public int OpenFlags // WalkThru
            {
                set { base.common = value ; }
                get { return base.common; }
            }
            public int KeyCode { set; get; }
        }

        public class SceneryProtoStairsData : SceneryProtoCommonData
        {
            public int ElavationTile
            {
                set { base.common = value ; }
                get { return base.common; }
            }
            public int DestMapId { set; get; }
        }

        public class SceneryProtoElevatorData : SceneryProtoCommonData
        {
            public int ElevatorTypeID
            {
                set { base.common = value ; }
                get { return base.common; }
            }
            public int ElevatorLevel { set; get; }
        }

        public class SceneryProtoLadderData : SceneryProtoCommonData
        {
            public int EelevationAndTile
            {
                set { base.common = value; }
                get { return base.common; }
            }
        }
    }
}
